//package com.xzs.data.mq;
//
//import org.springframework.amqp.core.Binding;
//import org.springframework.amqp.core.BindingBuilder;
//import org.springframework.amqp.core.DirectExchange;
//import org.springframework.amqp.core.Queue;
//import org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory;
//import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
//import org.springframework.amqp.rabbit.connection.ConnectionFactory;
//import org.springframework.amqp.rabbit.core.RabbitAdmin;
//import org.springframework.amqp.rabbit.core.RabbitTemplate;
//import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//
///**
// * @author reolfan
// * @date create by in 2020-01-20 13:44
// */
//@Configuration
//public class DirectRabbitConfig {
//    @Value("${rabbitmq.exchange.deliver}")
//    private String deliverExchange;
//    @Value("${rabbitmq.routingkey}")
//    private String routingkey;
//
//    @Bean
//    public ConnectionFactory connectionFactory() {
//        CachingConnectionFactory connectionFactory = new CachingConnectionFactory();
//        connectionFactory.setUri("amqp://guest:guest@192.168.1.240:5672");
//        return connectionFactory;
//    }
//
//    @Bean
//    public Queue deliverEsQueue() {
//        return new Queue("xzs_test_3", true);
//    }
//
//    //Direct交换机
//    @Bean
//    DirectExchange deliverEsDirectExchange() {
//        return new DirectExchange(deliverExchange);
//    }
//
//    //绑定  将队列和交换机绑定, 并设置用于匹配键：
//    @Bean
//    Binding bindingDeliverDirect() {
//        return BindingBuilder.bind(deliverEsQueue()).to(deliverEsDirectExchange()).with(routingkey);
//    }
//
//    @Bean
//    public RabbitAdmin rabbitAdmin(ConnectionFactory connectionFactory) {
//        return new RabbitAdmin(connectionFactory);
//    }
//
//    @Bean
//    public RabbitTemplate rabbitTemplate(ConnectionFactory connectionFactory) {
//        RabbitTemplate template = new RabbitTemplate(connectionFactory);
//        template.setMessageConverter(new Jackson2JsonMessageConverter());
//        return template;
//    }
//
//    @Bean
//    public SimpleRabbitListenerContainerFactory rabbitListenerContainerFactory(ConnectionFactory connectionFactory) {
//        SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
//        factory.setConnectionFactory(connectionFactory);
//        factory.setMessageConverter(new Jackson2JsonMessageConverter());
//        return factory;
//    }
//}